/**
 * 功能描述 导航
 */
define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
	var roomStatus = require("../store/roomStatus");
	var enmu = require("enums");
    var instance = {
        initComponent: function (params,widget) {
        	var subnav = new Subnav({
        		parentNode:".J-subnav",
        		model:{
        			title:"房态设置",
        			items:[{
        				id:"search",
        				type:"search",
        				placeholder:"请输入房间编号",//"楼宇/房型/房态",
        				handler : function(str){
        					var grid = widget.get("grid");
        					var subnav = widget.get("subnav");
        					aw.ajax({
        						url:"api/room/search",
        						data:{
        							s:str,
        							searchProperties:"code",
        							fetchProperties:roomStatus.fetchProperties
        						},
        						dataType:"json",
        						success:function(data){
        							grid.setData(data);
        						}
        					});
        				}	
        				
        			},{
						id: "buildings",
						type: "buttongroup",
						tip: "楼宇",
						all: {
			                show: true,
			                position: "top",
			                text: "全部"
			            },
						url : "api/orgbuilding/query",
						keyField: "pkOrgBuilding",
						lazy : true,
						params : function(){
							fetchProperties:"pkOrgBuilding,name"
						},
						valueField: "name",
						handler: function(key,element){
							widget.get("subnav").load("roomTypes");
							widget.get("grid").refresh();
						}
					},{
						id: "roomTypes",
						type: "buttongroup",
						tip: "房型",
						all: {
			                show: true,
			                position: "top",
			                text: "全部"
			            },
						url : "api/roomtype/query",
						params : function(){
							return {
								fetchProperties:"pkRoomType,name",
								orgBuilding: subnav.getValue("buildings"),
							}
						},
						lazy : true,
						keyField: "pkRoomType",
						valueField: "name",
						handler: function(key){							
							widget.get("grid").refresh();
						}
					},{
						id: "status",
						type: "buttongroup",
						tip: "房态",
						items:enmu["com.eling.elcms.basedoc.model.Room.Status"],
						all: {
			                show: true,
			                position: "top",
			                text: "全部"
			            },						
						handler:function(key,element){
							widget.get("grid").refresh();
						}
					},{
        				
            			id : "betch",
    					type : "button",
    					text:"批量设置",						
    					handler:function(){
    						widget._betch(widget,true,null);
    					}
    					
        			}]
        		}
        	});
        	widget.set("subnav",subnav);
        }
    };
    module.exports = instance;
});
